using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.Collections;

namespace CtxReader {
	static class Program {

		static void Main() {
			DAL dal=new DAL("pon-wpsq04-db","rf");
			byte[] stateBytes=(byte[])dal.Scalar("select top 1 state from rfState order by lastupdate desc");
			MemoryStream ms=new MemoryStream();
			BinaryFormatter bf=new BinaryFormatter();
			ms.Write(stateBytes,0,stateBytes.Length);
			ms.Seek(0,0);
			bf.Binder=new DeserializationBinder();
			CtxReader.Context.ContextProperties _properties=(CtxReader.Context.ContextProperties)bf.Deserialize(ms);
			ms.Close();


		}
	}

	class DeserializationBinder:SerializationBinder {
		public override Type BindToType(string assemblyName,string typeName) {

			if(typeName.Contains("ContextProperties"))
				return typeof(CtxReader.Context.ContextProperties);
			else if(typeName.Contains("OutputFrame"))
				return typeof(OutputFrame);

			else if(typeName.Contains("Hashtable"))
				return typeof(Hashtable);

			throw new Exception("Unknown type "+typeName);
		}


	}
}